package com.deyinet.bdcms.service.impl;

import com.deyinet.bdcms.core.dao.Dao;
import com.deyinet.bdcms.core.service.impl.BaseServiceImpl;
import com.deyinet.bdcms.core.vo.Page;
import com.deyinet.bdcms.dao.IAlarmDao;
import com.deyinet.bdcms.entity.Alarm;
import com.deyinet.bdcms.entity.Devicedata;
import com.deyinet.bdcms.service.IAlarmServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/10/17 0017.
 */
@Service
public class AlarmServer extends BaseServiceImpl<Alarm> implements IAlarmServer {

    @Autowired
    private IAlarmDao alarmDao;

    @Override
    protected Dao getDao() {
        return alarmDao;
    }

    @Override
    public void flushAlarm(String sn) {
        alarmDao.flushAlarm(sn);
        return ;
    }

    @Override
    public void getAlarmNum(Map<String, Integer> info) {
        Alarm alarm =new Alarm();
        Long count=alarmDao.countByExampleEq(alarm);
        info.put("allAlarmNum",count.intValue());
        info.put("deviceAlarmNum",alarmDao.deviceAlarmCount(alarm));
        info.put("lastAlarmID",alarmDao.lastAlarm());
    }

    @Override
    public Map<String, Object> getlastAlarm() {
        return alarmDao.getlastAlarm();
    }

    @Override
    public void findByExampleLike(Alarm example, Page<Alarm> page, Timestamp beginTime, Timestamp endTime) {
        List<Alarm> list=alarmDao.findByExampleLike(example,page.getPageCurrent(),page.getPageSize(),beginTime,endTime);
        long count = alarmDao.countByExampleLike(example,beginTime,endTime);
        page.setList(list);
        page.setTotalRow(Long.valueOf(count));
    }
}
